给出个5字符串"hello" "yes" "manager" "worker" "no",编写一个Java程序,输出字符串长度最长的字符串。

来源:百度知道 编辑:UC知道 时间:2024/05/25 09:13:17

public class CompareStringLength
{
public static void main(String[] args){
String[] stringArray = new String[]{"hello", "yes", "manager", "worker", "no"};
CompareStringLength csl = new CompareStringLength();
System.out.println(csl.compareString(stringArray));
}

public String compareString(String[] strArray){
String temp = null;
int strLength = 0;
for(int i = 0 ; i < strArray.length; i++ ){
if(strArray[i].length() > strLength){
strLength = strArray[i].length();
temp = strArray[i];
}
}
return temp;
}
}

public class Temp {

public static void main(String[] args) {
String res = "";
String[] a = {"hello", "yes", "manager", "worker", "no"};
int length = -1;
for (int i = 0; i &